﻿using IDal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dal
{
    public class RecipeDal<T> : IRecipeDal<T> where T : class

    {

         public RecipeDal(MyContext context)
        {
            Context = context;
        }

        public MyContext Context { get; }

        public async Task<int> AddAnync(T t)
        {
            await Context.Set<T>().AddAsync(t);
             return await Context.SaveChangesAsync();

        }

        public async  Task<int> AddRangeAnync(List<T> list)
        {
            await Context.Set<T>().AddRangeAsync(list);
            return await Context.SaveChangesAsync();
        }

        public async  Task<int> DeleteAnync(T t)
        {
             Context.Set<T>().Remove(t);
            return await Context.SaveChangesAsync();
        }

        public async  Task<int> DeleteRangeAnync(List<T> list)
        {

            Context.Set<T>().RemoveRange(list);
            return await Context.SaveChangesAsync();
        }

        public IQueryable<T> GetAllAnync()
        {
            return Context.Set<T>();

        }

        public async Task<int> UpdateAnync(T t)
        {
            Context.Set<T>().Update(t);
            return await
               Context.SaveChangesAsync()
               ;
        }

        public async  Task<int> UpdateRageAnync(List<T> list)
        {
            Context.Set<T>().UpdateRange(list);
            return await
               Context.SaveChangesAsync()
               ;
        }
    }
}
